package src.linkeLlist;

public class no24 {
    public static void main(String[] args) {

    }

    //head -> 1 -> 2 -> 3 -> 4，temp1指1，temp2指3，初始p指dummy
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(0,head);
        dummy.next = head;
        ListNode p = dummy;
        while (p.next != null && p.next.next != null) {
            ListNode temp1 = p.next;
            ListNode temp2 = p.next.next.next;
            p.next = p.next.next;
            p.next.next = temp1;
            temp1.next = temp2;
            p = p.next.next;
        }
        return dummy.next;

    }
}
